var url = require('url');
var template = require('templateConfig');
var main = require('main');
var form = require('form');
var module= require("module");

//模板配置
var tplArr = [];
var modalTpl =require('raw!../template/modal.txt'); 
var personalTpl =require('raw!../template/personal-center.txt'); 
var indexTpl =require('raw!../template/comission.txt'); 
tplArr['modal'] = template.compile(modalTpl.replace(/^\s*|\s*$/g, "")); 
tplArr['personal'] = template.compile(personalTpl.replace(/^\s*|\s*$/g, "")); 
tplArr['index'] = template.compile(indexTpl.replace(/^\s*|\s*$/g, "")); 
 
function Index(){
    _this = this;
    this.main = function(){
        main.event(this,'tap','i-click'); 
        this.init();
    }     

    /**
     * @param  {string} page "come from which page"
     * 个人中心首页
     */
    this.getContent= function(page){
        var baseUrl= _this.baseUrl;
        var data= {
            tType: "content"
        };
        var data_body= {
            tType: "contentbody",
        }
        var data1 = {"list":[
                {"name":"累计粉丝数","key":"1011"},
                {"name":"累计佣金笔数","key":"1000"},
                {"name":"累计佣金额","key":"0"},
            ]};
        //个人信息
        var data_headblock= {
            tType: "headblock",
            image: "",
            title: "Golan Yao",
            tag: "普通店员",
            content: [{
                key: "店员编号",
                value: "123"
            }],
            qrcode: ""
        }; 
        var data_table = {
            tType: 'table',
            title: "佣金总排行榜",
            tabList:[
            // {
            //     time: "2016-11-11",
            //     num: "12345678",
            //     name: "Golan",
            //     money: "127.00",
            //     commission: "127.00",
            //     link: "",
            //     status: "已收货"
            // },{
            //     time: "2016-11-11",
            //     num: "12345678",
            //     name: "Golan",
            //     money: "127.00",
            //     commission: "127.00",
            //     link: "",
            //     status: "已收货"
            // },{
            //     time: "2016-11-11",
            //     num: "12345678",
            //     name: "Golan",
            //     money: "127.00",
            //     commission: "127.00",
            //     link: "",
            //     status: "已收货"
            // }
            ]
        }

         main.get(url.my_yj,{"openid":"testopenid"},function(res){
            console.log(res.code);
            data_headblock.title=res.data.info.clerk_name;
            data1.list[0].key=res.data.info.counts;
            data1.list[1].key=res.data.tongji.counts;
            data1.list[2].key=res.data.tongji.countprice;

            $.each(res.data.data, function(i, v){ 
                console.log(i);
                console.log(v);
                var sin={
                    time: v.add_time,
                    num: v.order_sn,
                    name: v.clerk_name,
                    money: v.xiaoshou_price,
                    commission: v.money,
                    link: "",
                    status: "已收货"
                }
                
                console.log(sin);
                data_table.tabList.push(sin);
            });

            data.headblock= module.getModule(data_headblock, "headblock"); 
            data.triple= module.getModule(data1, "InfoTiled");
            data.table= tplArr['index'](data_table);
            $(".content").html(tplArr['index'](data)); 

         })
         
    } 

    //inital page
    this.init= function(){  
        this.baseUrl= url.baseImageUrl+'/img/'; 
        this.getContent();
    }
    return this.main();
};

var index = new Index();